public class Solution1052 {
    public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
        int[] sum=new int[customers.length+1];
        int total=0;
        for (int i=0;i<customers.length;i++){
            if (grumpy[i]==1){
                sum[i+1]=sum[i]+customers[i];
            }else{
                sum[i+1]=sum[i];
                total=total+customers[i];
            }
        }
        int max=0;
        for (int i=minutes;i<=customers.length;i++){
            max=Math.max(max,sum[i]-sum[i-minutes]);
        }
        return total+max;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1052().maxSatisfied(new int[]{1,0,1,2,1,1,7,5},new int[]{0,1,0,1,0,1,0,1},3));
    }
}
